﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace week2.classes
{
    class ATM
    {
        private static Account Myaccount;
        private static Bank Mybank;
        private static bool Existedacc;//账户是否存在

        public bool Logsuccess()
        {
            return Existedacc;
        }
        public Account GetAccount()
        {
            return Myaccount;
        }

        public ATM(Bank bank,string username,string pwd)//接入银行账户系统
        {
            Mybank = bank;
            Myaccount = bank[username];
            if (Myaccount == null) Existedacc = false;
            else if (!Myaccount.Login(pwd)) Existedacc = false;
            else Existedacc = true;
        }

        public static bool SaveM(int money)
        {
            if (!Existedacc) return false;
            return Myaccount.SaveM(money);
        }

        public static bool WithdrowM(int money)
        {
            if (!Existedacc) return false;
            return Myaccount.WithDraw(money);
        }

    }
}
